import { request } from '@pkg/request/src';

export enum Api {
  page = '/company/page',
  companyList = '/company/list',
  get = '/company/get',
  add = '/company/save',
  update = '/company/edit',
  remove = '/company/delete',
  areaAll = '/area/all',
  rechargeAmount = '/company/rechargeAmount',
}

export const companyList = (params) =>
  request.get(
    { url: Api.companyList, params },
    {
      errorMessageMode: 'none',
      successMessageMode: 'none',
    },
  );

export const get = (params) =>
  request.get(
    {
      url: Api.get,
      params: params,
    },
    { errorMessageMode: 'none', successMessageMode: 'none' },
  );
export const rechargeAmount = (params) =>
  request.post(
    {
      url: Api.rechargeAmount,
      params: params,
    },
    { errorMessageMode: 'none', successMessageMode: 'none' },
  );

export const getAreaTreeList = (params) => {
  return request.get(
    {
      url: Api.areaAll,
      params: params,
    },
    {errorMessageMode: 'none', successMessageMode: 'none'},
  );
}


export function initAreaData(data) {
  let newData: any = []
  data.map((item) => {
    let label = item['areaName']
    let value = item['areaId']
    let children = item['child']
    if (children) {
      children = initAreaData(children)
    }
    let newItem = {
      label: label,
      value: value,
      children: children
    }
    newData.push(newItem)
  })
  return newData
}

